#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys, os, time
import Ice

try:
    HOME = os.environ['ROBOTS']
except KeyError:
    print 'ROBOTS environment variable is not currently defined.'
    sys.exit(0)

SLICE = os.path.join(HOME, 'slice')
FILE = os.path.join(SLICE, 'Robots.ice')
SRC = os.path.join(HOME, 'src')
sys.path.append(SRC)
Ice.loadSlice('--all -I/usr/share/slice', ['-I' + SLICE, FILE])

import Robots
import Util

class AMI_Model_moveI (object):

    def ice_response (self):
        pass

    def ice_exception (self, ex):
        pass

class AMI_Model_setGoalI (object):

    def ice_response (self):
        pass

    def ice_exception (self, ex):
        pass

class Client (Ice.Application):

    def run (self, argv):

        #robotFactory = Robots.RobotFactoryPrx.checkedCast(
        #    self.communicator().stringToProxy('RobotFactory:default -p 9997'))

        #query = IceGrid.QueryPrx.checkedCast(self.communicator().stringToProxy('Robots/Query'))
        #print query.findAllObjectsByType('::Robots::AgentTeam')
        
        #agentTeam1 = Robots.AgentTeamPrx.checkedCast(self.communicator().stringToProxy('AgentTeam.1'))

        #robots = robotFactory.create(['192.168.1.2'])
        #agents = agentTeam1.create(['r1', 'r2'])

        A = Robots.AgentPrx.checkedCast(self.communicator().stringToProxy('A -t:tcp -h 192.168.161.92 -p 9898'))
        B = Robots.AgentPrx.checkedCast(self.communicator().stringToProxy('B -t:tcp -h 192.168.161.92 -p 9898'))
        C = Robots.AgentPrx.checkedCast(self.communicator().stringToProxy('C -t:tcp -h 192.168.161.92 -p 9898'))
        D = Robots.AgentPrx.checkedCast(self.communicator().stringToProxy('D -t:tcp -h 192.168.161.92 -p 9898'))
        #E = Robots.AgentPrx.checkedCast(self.communicator().stringToProxy('E -t:tcp -h 192.168.161.92 -p 9898'))

        agents = [A, B, C, D]

        for ag in agents:
            ag.setGoal_async(AMI_Model_setGoalI(),
                             Robots.SpreadGoal(Robots.Vec2(100, 50), 10.0))

        return 0

Client().main(sys.argv)
